#include "av.h"

extern
int lua_find_decoder(lua_State * L) {
	enum CodecID id = lua_check_codec_id(L, 1);
	AVCodec * codec = avcodec_find_decoder(id);
	if (!codec) {
		luaL_error(L, "Unable to find a matching codec");
		return 0;
	}
	lua_push_codec(L, codec);
	return 1;
}

extern
int lua_find_encoder(lua_State * L) {
	enum CodecID id = lua_check_codec_id(L, 1);
	AVCodec * codec = avcodec_find_encoder(id);
	if (!codec) {
		luaL_error(L, "Unable to find a matching codec");
		return 0;
	}
	lua_push_codec(L, codec);
	return 1;
}

DEFINE_TYPE_STRUCT(codec, AVCodec,
	LUA_OBJECT_CODEC_ID, av_free, 0)

DEFINE_INDEX_HEADER(codec, AVCodec)
DEFINE_INDEX_TRAILER()

DEFINE_NEWINDEX_HEADER(codec, AVCodec)
DEFINE_NEWINDEX_TRAILER()

DEFINE_OBJECT_FUNCTIONS(codec, AVCodec)
